//
//  MBProgressHUD+IPCamera.m
//  IPCamera
//
//  Created by 宣佚 on 15/5/28.
//  Copyright (c) 2015年 宣佚. All rights reserved.
//

#import "MBProgressHUD+IPCamera.h"

@implementation MBProgressHUD (IPCamera)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.color = [UIColor colorWithRed:0.173 green:0.243 blue:0.314 alpha:0.7];
    
    hud.labelText = text;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hide:YES afterDelay:1.5];
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view{
    [self show:error icon:@"icon-error.png" view:view];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view
{
    [self show:success icon:@"icon-success.png" view:view];
}

+ (void)showInfo:(NSString *)info toView:(UIView *)view
{
    [self show:info icon:@"icon-info.png" view:view];
}

#pragma mark 显示一些信息

+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.color = [UIColor colorWithRed:0.173 green:0.243 blue:0.314 alpha:0.7];
    
    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    return hud;
}

+(MBProgressHUD *) showMessageinTheWindow:(NSString *)message
{
    MBProgressHUD *MBPHud = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
    
    MBPHud.color = [UIColor colorWithRed:0.173 green:0.243 blue:0.314 alpha:0.7];
    
    [[UIApplication sharedApplication].keyWindow addSubview:MBPHud];
    [MBPHud show:YES];
    
    MBPHud.mode = MBProgressHUDModeText;
    MBPHud.labelText = message;
    MBPHud.margin = 10.f;
    MBPHud.yOffset = 150.f;
    MBPHud.removeFromSuperViewOnHide = YES;
    
    [MBPHud hide:YES afterDelay:1.2];
    return MBPHud;
}

+ (void)showSuccessinTheWindow:(NSString *)success
{
    [self showSuccess:success toView:[UIApplication sharedApplication].keyWindow];
}

+ (void)showSuccess:(NSString *)success
{
    [self showSuccess:success toView:nil];
}

+ (void)showError:(NSString *)error
{
    [self showError:error toView:nil];
}

+ (void)showInfo:(NSString *)info
{
    [self showInfo:info toView:nil];
}

+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}

+ (MBProgressHUD *)showWaiting
{
    return [self showMessage:@"处理中 请稍等" toView:nil];
}

+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    [self hideHUDForView:view animated:YES];
}

+ (void)hideHUD
{
    [self hideHUDForView:nil];
}

@end
